package com.feeling.oafeeling.service.impl;

import com.feeling.oafeeling.mapper.CheckApprovalProcessMapper;
import com.feeling.oafeeling.mapper.CheckReviewRuleMapper;
import com.feeling.oafeeling.mapper.SysUserMapper;
import com.feeling.oafeeling.pojo.SysUser;
import com.feeling.oafeeling.service.ICheckApprovalProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : LiuLi
 * @create 2023/6/25 14:42
 */

@Repository
public class CheckApprovalProcessServiceImpl implements ICheckApprovalProcessService {

    @Autowired
    private CheckApprovalProcessMapper processMapper;

    @Autowired
    private SysUserMapper sysUser;

    @Autowired
    private CheckReviewRuleMapper checkReviewRuleMapper;

    @Override
    public List<Integer> getIfUserTask(String orderType, String orderStatus, Long userid) {
        int num = 0;
        int roleId;
        if ("START".equals(orderStatus)){
            num = 1;
        }else if (!"OVER".equals(orderStatus)){
            num = Integer.valueOf(orderStatus) + 1;
        }
//        if ("NO".equals(orderType)){
        List<Integer> list = processMapper.getByNoTypeId(num);
//        }else {
//            roleId = processMapper.getRoleId(orderType,num);
//        }
        ArrayList arrayList = new ArrayList();
        Integer insId = checkReviewRuleMapper.getInstiutionId(num);
        SysUser fromId = sysUser.findFromId(userid);
        int deptId = Integer.valueOf(fromId.getDeptId().toString());
        int user = Integer.valueOf(String.valueOf(userid));
        System.out.println("================================");
        System.out.println(deptId);
        System.out.println(insId);
        for (Integer integer : list) {
            System.out.println(integer);
            if (integer == user){
                arrayList.add(integer);
            }else if (integer == 0 && insId == deptId){
                arrayList.add(integer);
            }
        }
        if (list.size() == 0 ){
            return arrayList;
        }
        return arrayList;
    }

    @Override
    public String getAppProId(Integer orderId) {
        return processMapper.getAppProId(orderId);
    }
}
